//package com.itgone.easyblog.service.image.impl;
//
//import cn.hutool.core.io.FileUtil;
//import cn.hutool.http.HttpUtil;
//import com.itgone.easyblog.config.BlogServiceException;
//import com.itgone.easyblog.service.image.IFileUploadService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.File;
//import java.io.IOException;
//
////@Service
//public class LocalFileService implements IFileUploadService {
//    private static final Logger logger = LoggerFactory.getLogger(LocalFileService.class);
//
//    private final Integer uploadServerPort = 9000;
//    private final String uploadBootDir = "E:\\temp";
//
//    public void startService() {
//        HttpUtil.createServer(uploadServerPort)
//                // 设置默认根目录
//                .setRoot(uploadBootDir)
//                .start();
//
//        logger.info("本地文件服务器启动成功，root:{}，port:{}", uploadBootDir, uploadServerPort);
//    }
//
//    @Override
//    public String upload(MultipartFile uploadFile) {
//        String fileName = uploadFile.getOriginalFilename();
//        assert fileName != null;
//        File targetFile = new File(uploadBootDir, fileName);
//        byte[] bytes;
//        try {
//            bytes = uploadFile.getBytes();
//        } catch (IOException e) {
//            logger.error("uploadFile.getBytes failed", e);
//            throw new BlogServiceException("文件上传失败");
//        }
//        File file = FileUtil.writeBytes(bytes, targetFile);
//        String name = FileUtil.getName(file);
//        return "http://localhost:" + uploadServerPort + "/" + name;
//    }
//}
